package gosopt

import (
	"strings"

	"gitee.com/haifengat/gosopt/define"
	"golang.org/x/text/encoding/simplifiedchinese"
)

type ReqConnectType func(string)
type ReleaseAPIType func()
type ReqUserLoginType func(*define.CThostFtdcReqUserLoginField)

// quote
type ReqSubscriptType func(string)

func Bytes2String(t []byte) string {
	msg, _ := simplifiedchinese.GB18030.NewDecoder().Bytes(t)
	return strings.Trim(string(msg), "\u0000")
}

// 产品类型
type ProductClassType byte

const (
	// 期货
	THOST_FTDC_PC_Futures = '1'
	// 期货期权
	THOST_FTDC_PC_Options = '2'
	// 组合
	THOST_FTDC_PC_Combination = '3'
	// 即期
	THOST_FTDC_PC_Spot = '4'
	// 期转现
	THOST_FTDC_PC_EFP = '5'
	// 现货期权
	THOST_FTDC_PC_SpotOption = '6'
	// 个股期权
	THOST_FTDC_PC_ETFOption = '7'
	// 证券
	THOST_FTDC_PC_Stock = '8'
)

// 持仓类型
type PositionTypeType byte

const (
	// 净持仓
	THOST_FTDC_PT_Net = '1'
	// 综合持仓
	THOST_FTDC_PT_Gross = '2'
)

// 期权类型
type OptionsTypeType byte

const (
	// 看涨
	THOST_FTDC_CP_CallOptions = '1'
	// 看跌
	THOST_FTDC_CP_PutOptions = '2'
)

// 组合类型类型
type CombinationTypeType byte

const (
	// 期货组合
	THOST_FTDC_COMBT_Future = '0'
	// 垂直价差BUL
	THOST_FTDC_COMBT_BUL = '1'
	// 垂直价差BER
	THOST_FTDC_COMBT_BER = '2'
	// 跨式组合
	THOST_FTDC_COMBT_STD = '3'
	// 宽跨式组合
	THOST_FTDC_COMBT_STG = '4'
	// 备兑组合
	THOST_FTDC_COMBT_PRT = '5'
	// 时间价差组合
	THOST_FTDC_COMBT_CLD = '6'
)

// 持仓多空方向类型
type PosiDirectionType byte

const (
	// 净
	THOST_FTDC_PD_Net = '1'
	// 多头
	THOST_FTDC_PD_Long = '2'
	// 空头
	THOST_FTDC_PD_Short = '3'
)

type HedgeFlagType byte

const (
	// 投机
	THOST_FTDC_HF_Speculation = '1'
	// 套利
	THOST_FTDC_HF_Arbitrage = '2'
	// 套保
	THOST_FTDC_HF_Hedge = '3'
	// 备兑
	THOST_FTDC_HF_Covered = '4'
	// 做市商
	THOST_FTDC_HF_MarketMaker = '5'
)

// 买卖方向
type DirectionType byte

const (
	// 买
	THOST_FTDC_D_Buy = '0'
	// 卖
	THOST_FTDC_D_Sell = '1'
)

// 开平标志类型
type OffsetFlagType byte

const (
	// 开仓
	THOST_FTDC_OF_Open = '0'
	// 平仓
	THOST_FTDC_OF_Close = '1'
	// 强平
	THOST_FTDC_OF_ForceClose = '2'
	// 平今
	THOST_FTDC_OF_CloseToday = '3'
	// 平昨
	THOST_FTDC_OF_CloseYesterday = '4'
	// 强减
	THOST_FTDC_OF_ForceOff = '5'
	// 本地强平
	THOST_FTDC_OF_LocalForceClose = '6'
)

// 报单状态类型
type OrderStatusType byte

const (
	// 全部成交
	THOST_FTDC_OST_AllTraded = '0'
	// 部分成交还在队列中
	THOST_FTDC_OST_PartTradedQueueing = '1'
	// 部分成交不在队列中
	THOST_FTDC_OST_PartTradedNotQueueing = '2'
	// 未成交还在队列中
	THOST_FTDC_OST_NoTradeQueueing = '3'
	// 未成交不在队列中
	THOST_FTDC_OST_NoTradeNotQueueing = '4'
	// 撤单
	THOST_FTDC_OST_Canceled = '5'
	// 未知
	THOST_FTDC_OST_Unknown = 'a'
	// 尚未触发
	THOST_FTDC_OST_NotTouched = 'b'
	// 已触发
	THOST_FTDC_OST_Touched = 'c'
)

type InstrumentStatusType byte

const (
	// 开盘前
	THOST_FTDC_IS_BeforeTrading = '0'
	// 非交易
	THOST_FTDC_IS_NoTrading = '1'
	// 连续交易
	THOST_FTDC_IS_Continous = '2'
	// 集合竞价报单
	THOST_FTDC_IS_AuctionOrdering = '3'
	// 集合竞价价格平衡
	THOST_FTDC_IS_AuctionBalance = '4'
	// 集合竞价撮合
	THOST_FTDC_IS_AuctionMatch = '5'
	// 收盘
	THOST_FTDC_IS_Closed = '6'
	// 集合竞价
	THOST_FTDC_IS_Auction = '7'
	// 休市
	THOST_FTDC_IS_BusinessSuspension = '8'
	// 波动性中断
	THOST_FTDC_IS_VolatilityInterrupt = '9'
	// 临时停牌
	THOST_FTDC_IS_TemporarySuspension = 'a'
	// 收盘集合竞价
	THOST_FTDC_IS_AuctionAfterClosed = 'b'
	// 可恢复交易的熔断
	THOST_FTDC_IS_ResumableFusing = 'c'
	// 不可恢复交易的熔断
	THOST_FTDC_IS_UnResumableFusing = 'd'
	// 盘后交易
	THOST_FTDC_IS_TradingAfterClosed = 'e'
)
